//添加学员资料
$(".btn-students").click(function() {
    var user_name = $("input[name='user_name']").val();
    if (user_name == '') {
        parent.layer.msg("学员姓名不能为空");
        return false
    }
    var identity_card = $("#identity_card").val();
    if (identity_card == '') {
        parent.layer.msg("学员身份证不能为空");
        return false
    }
    var phone = $("input[name='phone']").val();
    if (phone == '') {
        parent.layer.msg("学员手机号码不能为空");
        return false
    }
    if(!(/^1[3456789]\d{9}$/.test(phone))){  
        parent.layer.msg("手机号码不合法，请重新输入"); 
        return false; 
    } 
    var school_name = $("input[name='school_name']").val();
    if (school_name == '') {
        parent.layer.msg("报考学校不能为空");
        return false
    }
    var type = $("#type option:selected").val();
    if (type == '0') {
        parent.layer.msg("请选择一个报考类型");
        return false
    }
    if(type == 7){
        var hierarchy = $("input[name='hierarchy']").val();
        if (hierarchy == '') {
            parent.layer.msg("请填写报考层次");
            return false
        }
    }else{
        var hierarchy = $("#gradation_s option:selected").val();
        if (hierarchy == '0') {
            parent.layer.msg("请选择报考层次");
            return false
        }
    }
    var professional = $("input[name='professional']").val();
    if (professional == '') {
        parent.layer.msg("请填写报考专业");
        return false
    }
    var address = $("input[name='address']").val();
    if (address == '') {
        parent.layer.msg("请填写考试地址");
        return false
    }
    $.post("/manage/addStudentMaterial", {
        user_name: user_name,
        identity_card: identity_card,
        phone: phone,
        school_name: school_name,
        type: type,
        hierarchy: hierarchy,
        professional: professional,
        address: address,
    }, function(result) {
        parent.layer.msg(result['msg']);
        if(result['code'] == 1){
            $("#modal-demo").modal("hide");
            setTimeout(function(){
                location.reload();
            },1000);
        } 
    })
})
//根据报考类型查询层次
$('#type').change(function(){
    var selectedValue = $(this).val();//选中的值
    if(selectedValue == 0) {
        $("#gradation").html('<select id="gradation_s" disabled class="form-control m-b" name="hierarchy"><option value="0">请选择</option></select>');
        return false;
    }
    if(selectedValue == 7){
        $("#gradation").html('<input type="text" placeholder="填写资格证类型" name="hierarchy" class="form-control">');
    }else{
        $.post("/manage/ajaxType", {
            pid: selectedValue,
        }, function(array) {
            var html = '<select id="gradation_s" class="form-control m-b" name="hierarchy">';
            for (let index = 0; index < array.length; index++) {
                html += '<option value="'+array[index].name+'">'+array[index].name+'</option>';
            }
            html += '</select>';
            $("#gradation").html(html);
        })
    }
 });
  //添加缴费记录
 $(".btn-cost").click(function(){
    var agreement_price = $("input[name='agreement_price']").val();
    if(agreement_price == ''){
        parent.layer.msg("请输入协议金额");
        return false
    }
    var submit_price = $("input[name='submit_price']").val();
    if(submit_price == ''){
        parent.layer.msg("请填写已交金额");
        return false
    }
    var order_sn = $("input[name='order_sn']").val();
    $.post("/manage/addCost", {
        agreement_price: agreement_price,
        submit_price: submit_price,
        order_sn: order_sn,
    }, function(result) {
        parent.layer.msg(result['msg']);
        if(result['code'] == 1){
            setTimeout(function(){
                openTabPage("/manage/listCost",'缴费记录');
            },2000);
        }
    })
 })
 //补交学费
 $(".btn-cost-supplement").click(function(){
    var supplement_price = $("input[name='supplement_price']").val();//补交金额
    if(supplement_price == ''){
        parent.layer.msg("请填写补交金额");
        return false
    }
    $.post("/manage/ajaxSupplement", {
        order_sn: $("input[name='order_sn']").val(),
        supplement_price:supplement_price
    }, function(result) {
        parent.layer.msg(result['msg']);
        if(result['code'] == 1){
            setTimeout(function(){
                openTabPage("/manage/listCost",'缴费记录');
            },2000);
        }
    })
 })
 //分公司审核
 $(".bt-audit").click(function(){
    id = $(this).attr('data-id');
    status = $(this).attr('data-status');
    parent.layer.confirm('确定要执行此操作？', {
        btn: ['确定','取消'], //按钮
        shade: false //不显示遮罩
    }, function(){
        index = parent.layer.load(0, {shade: false});//加载动画
        $.post("/manage/audit",{id:id,status:status},function(result){
            parent.layer.close(index);
            parent.layer.msg(result.msg);
            if(result.code == 1){
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
            }
        });
    }, function(){
        parent.layer.msg('操作取消');
    });
})
 //总公司审核
 $(".bt-total-audit").click(function(){
    id = $(this).attr('data-id');
    status = $(this).attr('data-status');
    parent.layer.confirm('确定要执行此操作？', {
        btn: ['确定','取消'], //按钮
        shade: false //不显示遮罩
    }, function(){
        index = parent.layer.load(0, {shade: false});//加载动画
        $.post("/manage/totalAudit",{id:id,status:status},function(result){
            parent.layer.close(index);
            parent.layer.msg(result.msg);
            if(result.code == 1){
                setTimeout(function() {
                    window.location.reload();
                }, 1000)
            }
        });
    }, function(){
        parent.layer.msg('操作取消');
    });
 })
 function myFunction(val){
	var agreement_price = $("input[name='agreement_price']").val();
    
    if(val - agreement_price > 0){
        parent.layer.msg('已缴金额过高');
        $("input[name='submit_price']").val(0);
        return false
    }
    
}
function openTabPage(url, title) {
    var wpd = $(window.parent.document);
    var mainContent = wpd.find('.J_mainContent');
    var thisIframe = mainContent.find("iframe[data-id='"+ url +"']");
    var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ')
    pageTabs.find(".J_menuTab.active").removeClass("active");
    mainContent.find("iframe").css("display", "none");
    if(pageTabs.find(".J_menuTab[data-id='"+ url +"']").length > 0){
        // 选项卡已打开
        thisIframe.css("display", "inline");
        pageTabs.find(".J_menuTab[data-id='"+ url +"']").addClass("active");
    }else{
        $(window.parent.document).find('.J_menuTabs .page-tabs-content ').find(".J_menuTab.active").removeClass("active");
        $(window.parent.document).find('.J_mainContent').find("iframe").css("display", "none");
        var iframe = '<iframe class="J_iframe" name="iframe10000" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
            + '" seamless="" style="display: inline;"></iframe>';
        $(window.parent.document).find('.J_menuTabs .page-tabs-content ').append(
            ' <a href="javascript:;" class="J_menuTab active" data-id="'+url+'">' + title + ' <i class="fa fa-times-circle"></i></a>');
        $(window.parent.document).find('.J_mainContent').append(iframe);
    }    
}
